package com.zx.mes.hyl.test.io;

import org.junit.Test;

import java.io.*;

/**
 * 字符流测试
 * @author hyl
 * @date 2018-2-13
 */
public class IOTest2 {
    @Test
    public void test() throws IOException {
        String pathname = "C:\\Users\\Administrator\\IdeaProjects\\long-test-3\\src\\main\\resources\\java基础2.txt";
        File file = new File(pathname);
        InputStreamReader inr = new FileReader(file);
        OutputStreamWriter osw = new FileWriter("C:\\Users\\Administrator\\IdeaProjects\\long-test-3\\src\\main\\resources\\java基础3.txt");
        char[] chars = new char[128];
        int len = 0;
        while ((len = inr.read(chars))!=-1) {
            System.out.println(chars);
            osw.write(chars);
        }
        inr.close();
        osw.close();
    }

    @Test
    public void test2() throws IOException {
        String pathname = "C:\\Users\\Administrator\\IdeaProjects\\long-test-3\\src\\main\\resources\\java基础2.txt";
        File file = new File(pathname);
        Reader reader = new BufferedReader(new FileReader(file));
        Writer writer = new BufferedWriter(new FileWriter("C:\\Users\\Administrator\\IdeaProjects\\long-test-3\\src\\main\\resources\\java基础4.txt"));
        char[]chars=new char[128];
        int len = 0;
        while ((len=reader.read(chars))!=-1){
            System.out.println(chars);
            writer.write(chars);
        }
        reader.close();
        writer.close();
    }
}


